package com.ruiyian.project.event.controller;

import com.ruiyian.common.annotation.Log;
import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.page.TableDataInfo;
import com.ruiyian.common.enums.BusinessType;
import com.ruiyian.common.utils.poi.ExcelUtil;
import com.ruiyian.project.event.domain.EventRecord;
import com.ruiyian.project.event.service.IEventRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 事件记录Controller
 *
 * @author ruoyi
 * @date 2021-12-23
 */
@RestController
@RequestMapping("/event/eventrecord")
public class EventRecordController extends BaseController
{
    @Autowired
    private IEventRecordService eventRecordService;

    /**
     * 查询事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('event:eventrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(EventRecord eventRecord)
    {
        startPage();
        List<EventRecord> list = eventRecordService.selectEventRecordList(eventRecord);
        return getDataTable(list);
    }

    /**
     * 导出事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('event:eventrecord:export')")
    @Log(title = "事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EventRecord eventRecord)
    {
        List<EventRecord> list = eventRecordService.selectEventRecordList(eventRecord);
        ExcelUtil<EventRecord> util = new ExcelUtil<EventRecord>(EventRecord.class);
        util.exportExcel(list, "事件记录数据");
    }

    /**
     * 获取事件记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('event:eventrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eventRecordService.selectEventRecordById(id));
    }

    /**
     * 新增事件记录
     */
    @PreAuthorize("@ss.hasPermi('event:eventrecord:add')")
    @Log(title = "事件记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EventRecord eventRecord)
    {
        return toAjax(eventRecordService.insertEventRecord(eventRecord));
    }

    /**
     * 修改事件记录
     */
    @PreAuthorize("@ss.hasPermi('event:eventrecord:edit')")
    @Log(title = "事件记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EventRecord eventRecord)
    {
        return toAjax(eventRecordService.updateEventRecord(eventRecord));
    }

    /**
     * 删除事件记录
     */
    @PreAuthorize("@ss.hasPermi('event:eventrecord:remove')")
    @Log(title = "事件记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eventRecordService.deleteEventRecordByIds(ids));
    }
}
